<template>
  <div class="Detail-Container">
    <!-- 头部区域 -->
    <div class="Detail-Header">
      <div class="Header-Left">
        <h1>管理团队</h1>
        <button class="Manage-Back-Btn" @click="ToDetail">
          <i class="icon-back"></i> 返回
        </button>
      </div>
    </div>

    <!-- 标签页容器 -->
    <div class="tab-container">
      <div class="tab-inside">
        <!-- 主标签栏 -->
        <div class="tab-list">
          <button 
            class="tab-item" 
            data-tab="basic" 
            :class="{ active: activeTab === 'basic' }" 
            @click="activeTab = 'basic'"
          >
            基本信息
          </button>
          <button 
            class="tab-item" 
            data-tab="members" 
            :class="{ active: activeTab === 'members'}" 
            @click="activeTab = 'members', memberTab = 'formal'"
          >
            成员管理
          </button>
        </div>

        <!-- 标签内容区 -->
        <div class="tab-content">
          <!-- 基本信息面板 -->
          <div 
            class="tab-panel" 
            id="basic" 
            :class="{ active: activeTab === 'basic' }" 
            v-show="activeTab === 'basic'"
          >
            <div class="panel-card">
              <div class="panel-item">
                <label class="panel-label">团队名称</label>
                <div class="panel-content" v-if="!isEditing">
                  <span class="content-text">{{ curTeamName }}</span>
                </div>
                <div class="panel-content" v-else>
                  <input 
                    type="text" 
                    id="edit-teamName" 
                    v-model="editTeamName" 
                    placeholder="输入新队名" 
                    required
                    class="form-input"
                  />
                </div>
              </div>

              <div class="panel-item">
                <label class="panel-label">团队头像</label>
                <div class="panel-content" v-if="!isEditing">
                  <div class="avatar-container">
                    <img :src="curTeamAvatar" alt="团队头像" class="detail-image" />
                  </div>
                </div>
                <div class="panel-content" v-else>
                  <div class="avatar-upload">
                    <label for="teamAvatar" class="upload-btn">
                      <i class="icon-upload"></i> 选择图片
                    </label>
                    <input 
                      type="file" 
                      id="teamAvatar" 
                      accept="image/*" 
                      @change="handleFileChange"
                      class="upload-input"
                    />
                    <div v-if="selectedImage" class="image-Preview">
                      <img :src="selectedImage" alt="团队头像预览" class="detail-image" />
                      <button class="remove-preview" @click="selectedImage = '', fileToUpload = null">
                        <i class="icon-close"></i>
                      </button>
                    </div>
                    <p class="upload-tip">支持JPG、PNG格式，建议尺寸200x200px，不超过5MB</p>
                  </div>
                </div>
              </div>

              <div class="panel-item">
                <label class="panel-label">公开程度</label>
                <div class="radio-group">
                  <label class="radio-item" v-for="item in opennessOptions" :key="item.value">
                    <input 
                      type="radio" 
                      name="openness" 
                      :value="item.value" 
                      v-model="selectedOpenness" 
                      :disabled="!isEditing"
                      class="radio-input"
                    />
                    <span class="radio-text">{{ item.label }}</span>
                  </label>
                </div>
              </div>

              <div class="panel-item">
                <label class="panel-label">团队描述</label>
                <div class="panel-content" v-if="!isEditing">
                  <span class="content-text">{{ Description || '暂无描述' }}</span>
                </div>
                <div class="panel-content" v-else>
                  <textarea 
                    id="edit-description" 
                    v-model="editDescription" 
                    placeholder="输入团队描述（最多200字）" 
                    required
                    class="form-textarea"
                    maxlength="200"
                  ></textarea>
                  <p class="count-tip">{{ editDescription.length }}/200</p>
                </div>
              </div>

              <div class="Edit-Box">
                <button class="btn btn-outline" @click="toggleEdit">
                  {{ isEditing ? '取消' : '修改内容' }}
                </button>
                <button class="btn btn-primary" @click="updateInfo" v-show="isEditing">
                  保存修改
                </button>
              </div>
            </div>
          </div>

          <!-- 成员管理面板 -->
          <div 
            class="tab-panel" 
            id="members" 
            :class="{ active: activeTab === 'members'}" 
            v-show="activeTab === 'members'"
          >
            <!-- 成员子标签栏 -->
            <div class="member-tab-list">
              <button 
                class="member-tab-item" 
                data-tab="pending" 
                :class="{ active: memberTab === 'pending' }" 
                @click="memberTab = 'pending'"
              >
                待审核
                <span v-if="pendingMembers.length > 0" class="badge">{{ pendingMembers.length }}</span>
              </button>
              <button 
                class="member-tab-item" 
                data-tab="formal" 
                :class="{ active: memberTab === 'formal'}" 
                @click="memberTab = 'formal'"
              >
                正式成员
                <span class="badge">{{ formalMembers.length }}</span>
              </button>
            </div>

            <!-- 操作按钮区 -->
            <div class="member-actions" v-show="memberTab === 'pending'">
              <button 
                class="btn btn-success" 
                @click="handleApproveSelected" 
                :disabled="!hasSelectedPendingMembers"
              >
                <i class="icon-check"></i> 批准选中
              </button>
              <button 
                class="btn btn-danger" 
                @click="handleRejectSelected" 
                :disabled="!hasSelectedPendingMembers"
              >
                <i class="icon-times"></i> 拒绝选中
              </button>
            </div>
            <div class="member-actions" v-show="memberTab === 'formal'">
              <button 
                class="btn btn-warning" 
                @click="handleRemoveSelected" 
                :disabled="!hasSelectedFormalMembers"
              >
                <i class="icon-trash"></i> 移除选中
              </button>
            </div>
            
            <!-- 待审核成员列表 -->
            <div class="member-card" v-show="memberTab === 'pending'">
              <div class="member-list-header">
                <div class="list-checkbox">
                  <input 
                    type="checkbox" 
                    v-model="pendingAllSelected" 
                    class="member-checkbox" 
                  />
                </div>
                <div class="list-username">用户名</div>
                <div class="list-pending">验证信息</div>
              </div>
              <div class="member-list-content">
                <div 
                  class="member-item" 
                  v-for="member in pendingMembers" 
                  :key="member.id"
                  :class="{ 'leader-item': member.username === curTeamLeader }"
                >
                  <div class="item-checkbox">
                    <input 
                      type="checkbox" 
                      v-model="member.selected" 
                      :disabled="member.username === curTeamLeader" 
                      class="member-checkbox"
                    />
                  </div>
                  <div class="item-username">
                    {{ member.username }}
                    <span v-if="member.username === curTeamLeader" class="leader-tag">队长</span>
                  </div>
                  <div class="item-pending">
                    <span class="pending-text">{{ member.pending || '申请加入团队' }}</span>
                  </div>
                </div>
                <div class="empty-state" v-if="pendingMembers.length === 0">
                  <i class="icon-empty"></i>
                  <p>暂无待审核的加入请求</p>
                </div>
              </div>
            </div>

            <!-- 正式成员列表 -->
            <div class="member-card" v-show="memberTab === 'formal'">
              <div class="member-list-header">
                <div class="list-checkbox">
                  <input 
                    type="checkbox" 
                    v-model="formalAllSelected" 
                    class="member-checkbox" 
                  />
                </div>
                <div class="list-username">用户名</div>
                <div class="list-remark">备注名</div>
                <div class="list-permission">权限</div>
                <div class="list-operation">操作</div>
              </div>
              <div class="member-list-content">
                <div 
                  class="member-item" 
                  v-for="member in formalMembers" 
                  :key="member.id"
                  :class="{ 'leader-item': member.username === curTeamLeader, 'editing-item': editingMemberID === member.id }"
                >
                  <div class="item-checkbox">
                    <input 
                      type="checkbox" 
                      v-model="member.selected" 
                      :disabled="member.username === curTeamLeader" 
                      class="member-checkbox"
                    />
                  </div>
                  <div class="item-container">
                    <div class="item-username">
                      {{ member.username }}
                      <span v-if="member.username === curTeamLeader" class="leader-tag">队长</span>
                    </div>
                    <div class="item-remark">
                      <template v-if="editingMemberID !== member.id">
                        <span class="remark-text">{{ member.remark || '无' }}</span>
                      </template>
                      <template v-else>
                        <input 
                          type="text" 
                          v-model="member.editRemark" 
                          required
                          class="form-input small-input"
                          placeholder="输入备注名"
                        />
                      </template>
                    </div>
                    <div class="item-permission">
                      <template v-if="!isAdmin || member.username === curTeamLeader">
                        <span class="permission-tag leader-tag">队长</span>
                      </template>
                      <template v-else>
                        <template v-if="editingMemberID === member.id">
                          <select 
                            v-model="member.editPermission" 
                            class="form-select small-select"
                          >
                            <option value="member">普通成员</option>
                            <option value="admin">管理员</option>
                          </select>
                        </template>
                        <template v-else>
                          <span 
                            class="permission-tag" 
                            :class="{ 'admin-tag': member.permission === 'admin', 'member-tag': member.permission === 'member' }"
                          >
                            {{ member.permission === 'admin' ? '管理员' : '普通成员' }}
                          </span>
                        </template>
                      </template>
                    </div>
                    <div class="item-operation">
                      <template v-if="member.username !== curTeamLeader">
                        <button 
                          class="btn btn-sm btn-outline" 
                          @click="toggleEditMember(member)"
                        >
                          {{ editingMemberID === member.id ? '取消' : '修改' }}
                        </button>
                        <button 
                          class="btn btn-sm btn-primary" 
                          @click="updatePermission(member)" 
                          v-show="editingMemberID === member.id"
                        >
                          保存
                        </button>
                      </template>
                      <template v-else>
                        <span class="no-operation">不可操作</span>
                      </template>
                    </div>
                  </div>
                </div>
                <div class="empty-state" v-if="formalMembers.length === 0">
                  <i class="icon-empty"></i>
                  <p>暂无正式成员</p>
                </div>
              </div>
              <div class="member-functions" v-if="formalMembers.length > 0">
                <div class="selected-count">已选中 {{ memSelected }} 名成员</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue';
import { useUserStore } from '@/stores/userStore';
import { useTeamStore } from '@/stores/teamStore';
import { useMemberStore } from '@/stores/memberStore';
import { useServer } from '@/components/ts/useServer';
import router from "@/router/index.ts";

// 状态管理
const userStore = useUserStore();
const teamStore = useTeamStore();
const memberStore = useMemberStore();
const { get, post, postFile } = useServer();
const testUrl = "https://m1.apifoxmock.com/m1/6951272-6668040-default/api";

// 路由跳转
const ToDetail = () => {
  router.push('/team/detail');
}

// 团队信息同步
onMounted(async () => {
  const currentTeam = teamStore.currentTeam;
  const currentUser = userStore.currentUserName;

  // 载入当前团队的内容
  if(currentTeam) {
    curTeamName.value = currentTeam.name;
    curteamID.value = currentTeam.id;
    curTeamLeader.value = currentTeam.admin;
    curTeamAvatar.value = currentTeam.thumbnail;
    Description.value = currentTeam.description;
    curTeamMember.value = currentTeam.member_count;

    if(currentUser === curTeamLeader.value) isAdmin.value = true;
  }

  if(curteamID.value) {
    memberStore.initTeamMembers(curteamID.value);
    await loadTeamMembers();
  }
})

// 团队详情相关状态
const isAdmin = ref(false);
const curTeamName = ref(''); 
const curTeamLeader = ref('');
const curteamID = ref(''); 
const curTeamMember = ref(0);
const Description = ref(''); 
const curTeamAvatar = ref('');
const selectedImage = ref('');
const fileToUpload = ref<File | null>(null);

// 公开程度选项
const opennessOptions = ref([
  { label: '加入无需审核', value: 'no_audit' },
  { label: '加入需要审核', value: 'need_audit' },
  { label: '不允许加入', value: 'not_allow' },
]);
const selectedOpenness = ref('need_audit');
const originOpenness = ref('need_audit');
const isEditing = ref(false);
const editTeamName = ref('');
const editDescription = ref('');
const activeTab = ref('basic');

// 成员管理相关状态
const memberTab = ref('formal');
const formalAllSelected = ref(false);
const pendingAllSelected = ref(false);
const editingMemberID = ref<number | null>(null);

// 计算属性 - 获取成员数据
const pendingMembers = computed(() => memberStore.getPendingMembers(curteamID.value) || []);
const formalMembers = computed(() => memberStore.getFormalMembers(curteamID.value) || []);

// 已选中正式成员数量
const memSelected = computed(() => {
  return formalMembers.value.filter(mem => mem.selected).length;
});

// 检查是否有待审核成员被选中
const hasSelectedPendingMembers = computed(() => {
  return pendingMembers.value.some(mem => mem.selected);
});

// 检查是否有正式成员被选中
const hasSelectedFormalMembers = computed(() => {
  return formalMembers.value.some(mem => mem.selected);
});

// 审核待审核成员 - 批准
const handleApproveSelected = async () => {
  const selectedMembers = pendingMembers.value.filter(mem => mem.selected);
  if (selectedMembers.length === 0) return;
  
  try {
    const res = await post('team/approveMembers', { teamID: curteamID.value, memberIds: selectedMembers.map(mem => mem.id) }, testUrl);
      if (res.success) {
        selectedMembers.forEach(mem => { 
          memberStore.removePendingMember(curteamID.value, mem.id); 
        });

        // 步骤2：将批准的成员转换为正式成员格式并添加到 store
        const formalMemberList = selectedMembers.map(mem => ({
          id: mem.id,
          username: mem.username,
          remark: '',
          permission: 'member' as const,
          selected: false,
          editRemark: '',
          editPermission: 'member' as const
        }));
        
        // 获取当前团队已有的正式成员，合并新成员
        const existingFormalMembers = memberStore.getFormalMembers(curteamID.value);
        memberStore.setFormalMembers(
          curteamID.value,
          [...existingFormalMembers, ...formalMemberList]
        );

        alert(`已成功批准 ${selectedMembers.length} 名成员加入团队`);
      } else {
        alert('批准失败: ' + (res.message || '未知错误'));
      }
  } catch(error) {
    console.error('批准成员失败', error);
    teamStore.error = '批准成员失败，请稍后重试';
  }
};

// 审核待审核成员 - 拒绝
const handleRejectSelected = async () => {
  const selectedMembers = pendingMembers.value.filter(mem => mem.selected);
  if (selectedMembers.length === 0) return;
  
  try {
    post('team/rejectMembers', { teamID: curteamID.value, memberIds: selectedMembers.map(mem => mem.id) }, testUrl)
      .then(res => {
        if (res.success) {
          selectedMembers.forEach(mem => {
            memberStore.removePendingMember(curteamID.value, mem.id);
          });
          alert(`已拒绝 ${selectedMembers.length} 名成员的加入请求`);
        }
      })
  } catch(error) {
    console.error('拒绝成员失败', error);
    teamStore.error = '操作失败，请稍后再试';
  }
};

// 移除正式成员
const handleRemoveSelected = async () => {
  const selectedMembers = formalMembers.value.filter(mem => mem.selected);
  if (selectedMembers.length === 0) return;
  
  const confirmRemove = confirm(`确定要移除选中的 ${selectedMembers.length} 名成员吗？`);
  if (!confirmRemove) return;
  
  try {
    const res = await post('team/removeMembers', { 
      teamID: curteamID.value, 
      memberIds: selectedMembers.map(mem => mem.id) 
    }, testUrl);
    
    if (res.success) {
      selectedMembers.forEach(mem => {
        memberStore.removeFormalMember(curteamID.value, mem.id);
      })
      alert(`已成功移除 ${selectedMembers.length} 名成员`);
    }
  } catch(error) {
    console.error('移除成员失败', error);
    teamStore.error = '操作失败，请稍后再试';
  }
};

// 成员编辑切换
const toggleEditMember = (member: typeof formalMembers.value[0]) => {
  if(editingMemberID.value !== null && editingMemberID.value !== member.id ) {
    alert('请先完成当前正在编辑的成员操作');
    return;
  }
  if (editingMemberID.value === member.id) {
    member.editRemark = member.remark;
    member.editPermission = member.permission;
    editingMemberID.value = null;
  } else {
    editingMemberID.value = member.id;
    member.editRemark = member.remark;
    member.editPermission = member.permission;
  }
}

// 更新成员权限
const updatePermission = async (member: typeof formalMembers.value[0]) => {
  try {
    const updateData = {
      teamID: curteamID.value,
      username: member.username,
      remarkName: member.editRemark, 
      permission: member.editPermission
    }
    post('team/updatePermission', updateData, testUrl)
      .then(res => {
        if(res.success) {
          memberStore.updateFormalMember(curteamID.value, {
            id: member.id,
            remark: updateData.remarkName,
            permission: updateData.permission
          });
          editingMemberID.value = null;
          alert('成员权限更新成功');
        }
      })
  } catch(error) {
    console.error('保存团队成员信息失败', error);
    teamStore.error = '保存失败，请稍后再试';
  }
}

// 团队编辑切换
const toggleEdit = () => {
  if(isEditing.value) {
    selectedOpenness.value = originOpenness.value;
    editTeamName.value = curTeamName.value;
    editDescription.value = Description.value;
    selectedImage.value = '';
    fileToUpload.value = null;
  } else {
    originOpenness.value = selectedOpenness.value;
  }
  isEditing.value = !isEditing.value;
}

// 更新团队信息
const updateInfo = async () => {
  if(!editTeamName.value.trim()) { 
    alert('请输入团队名称'); 
    return; 
  }
  
  if (editTeamName.value === curTeamName.value && 
      editDescription.value === Description.value && 
      selectedOpenness.value === originOpenness.value && 
      !selectedImage.value) {
    alert('未修改任何内容');
    isEditing.value = false;
    return;
  }

  const formData = new FormData();
  formData.append('teamID', curteamID.value);
  formData.append('teamName', editTeamName.value.trim());
  formData.append('openness', selectedOpenness.value);
  formData.append('description', editDescription.value.trim() || '');
  if (fileToUpload.value) {
    formData.append('teamAvatar', fileToUpload.value);
  }

  try {
    postFile('team/updateInfo', formData, testUrl)
      .then(res => {
        if(res.success) {
          const teamIndex = teamStore.teams.findIndex(team => team.id === curteamID.value);
          if(teamIndex !== -1) {
            if(fileToUpload.value) {
              teamStore.teams[teamIndex].thumbnail = URL.createObjectURL(fileToUpload.value);
              curTeamAvatar.value = URL.createObjectURL(fileToUpload.value);
            }
            teamStore.teams[teamIndex] = {
              ...teamStore.teams[teamIndex],
              name: editTeamName.value.trim(),
              description: editDescription.value.trim() || '',
              openness: selectedOpenness.value,
            };
          }

          if(teamStore.currentTeam?.id === curteamID.value) {
            teamStore.currentTeam = teamStore.teams[teamIndex];
          }
          
          curTeamName.value = editTeamName.value.trim();
          Description.value = editDescription.value.trim() || '';
          originOpenness.value = selectedOpenness.value;
          isEditing.value = false;
          selectedImage.value = '';
          fileToUpload.value = null;
          alert('团队信息修改成功');
        }
      })
  } catch(error) {
    console.error('保存团队信息失败', error);
    teamStore.error = '保存失败，请稍后再试';
  }
}

// 加载团队成员
const loadTeamMembers = async () => {
  if (!curteamID.value) return;
  
  try {
    const res = await get('team/getMembers', { teamID: curteamID.value }, testUrl);
    if (res.success) {
      // 格式化待审核成员数据
      const pending = res.pendingMembers.map((member: any) => ({
        id: member.id,
        username: member.username,
        pending: member.pendingReason || '申请加入团队',
        selected: false
      }));
      // 格式化正式成员数据
      const formal = res.formalMembers.map((member: any) => ({
        id: member.id,
        username: member.username,
        remark: member.remark || '',
        permission: member.permission as 'admin' | 'member',
        selected: false,
        editRemark: member.remark || '',
        editPermission: member.permission as 'admin' | 'member'
      }));

      memberStore.setPendingMembers(curteamID.value, pending);
      memberStore.setFormalMembers(curteamID.value, formal);
    } else {
      alert('获取成员列表失败');
    }
  } catch (error) {
    console.error('获取成员列表出错:', error);
    memberStore.setError(curteamID.value, '加载成员失败，请重试');
  }
};

// 监听待审核全选变化
watch(pendingAllSelected, (newVal) => {
  const selectableMembers = pendingMembers.value.filter(mem => mem.username !== curTeamLeader.value);
  selectableMembers.forEach(mem => mem.selected = newVal);
})

// 监听正式全选变化
watch(formalAllSelected, (newVal) => {
  const selectableMembers = formalMembers.value.filter(mem => mem.username !== curTeamLeader.value);
  selectableMembers.forEach(mem => mem.selected = newVal);
})

// 监听成员单选状态变化，自动更新全选状态
watch(
  () => pendingMembers.value.map(mem => mem.selected),
  () => {
    const selectable = pendingMembers.value.filter(mem => mem.username !== curTeamLeader.value);
    pendingAllSelected.value = selectable.length > 0 && selectable.every(mem => mem.selected);
  },
  { deep: true }
)

watch(
  () => formalMembers.value.map(mem => mem.selected),
  () => {
    const selectable = formalMembers.value.filter(mem => mem.username !== curTeamLeader.value);
    formalAllSelected.value = selectable.length > 0 && selectable.every(mem => mem.selected);
  },
  { deep: true }
)


// 处理文件上传
const handleFileChange = (e: Event) => {
  const input = e.target as HTMLInputElement;
  if (input.files && input.files[0]) {
    const file = input.files[0];

    // 检查文件大小
    if (file.size > 5 * 1024 * 1024) {
      alert("图片大小不能超过5MB");
      input.value = "";
      return;
    }

    // 检查文件类型
    const fileTypes = ['image/jpeg', 'image/png', 'image/jpg'];
    if (!fileTypes.includes(file.type)) {
      alert("请选择JPG或PNG格式的图片");
      input.value = "";
      return;
    }

    const reader = new FileReader();
    reader.onload = (e) => {
      selectedImage.value = e.target?.result as string;
    };
    reader.readAsDataURL(file);
    fileToUpload.value = file;
  } else {
    selectedImage.value = '';
    fileToUpload.value = null;
  }
};

// 初始化加载成员数据
loadTeamMembers();
</script>

<style scoped>
/* 基础样式重置与全局样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', 'Microsoft YaHei', sans-serif;
}

.Detail-Container {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f7fa;
  padding-bottom: 30px;
}

/* 头部样式 */
.Detail-Header {
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 20px 30px;
  margin-bottom: 20px;
}

.Header-Left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.Header-Left h1 {
  font-size: 24px;
  font-weight: 600;
  color: #1d2129;
}

.Manage-Back-Btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background-color: #f2f3f5;
  color: #4e5969;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

.Manage-Back-Btn:hover {
  background-color: #e5e6eb;
  color: #1d2129;
}

/* 标签页容器样式 */
.tab-container {
  width: 95%;
  max-width: 1400px;
  margin: 0 auto;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.tab-inside {
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* 主标签栏样式 */
.tab-list {
  display: flex;
  border-bottom: 1px solid #f2f3f5;
  background-color: #fff;
}

.tab-item {
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  color: #86909c;
  position: relative;
  transition: all 0.2s ease;
}

.tab-item:hover {
  color: #007bff;
}

.tab-item.active {
  color: #007bff;
  font-weight: 600;
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 3px;
  background-color: #007bff;
  border-radius: 3px 3px 0 0;
}

/* 标签内容区样式 */
.tab-content {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-panel.active {
  display: block;
}

/* 基本信息面板样式 */
.panel-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.panel-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 24px;
  position: relative;
}

.panel-label {
  width: 120px;
  font-size: 15px;
  font-weight: 500;
  color: #4e5969;
  text-align: left;
  padding-top: 10px;
  flex-shrink: 0;
}

.panel-content {
  flex: 1;
  padding-top: 6px;
}

.content-text {
  font-size: 15px;
  color: #1d2129;
  line-height: 1.5;
}

/* 表单元素样式 */
.form-input {
  width: 100%;
  max-width: 400px;
  padding: 10px 14px;
  border: 1px solid #d0d3d9;
  border-radius: 6px;
  font-size: 15px;
  color: #1d2129;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.form-textarea {
  width: 100%;
  max-width: 600px;
  min-height: 100px;
  padding: 10px 14px;
  border: 1px solid #d0d3d9;
  border-radius: 6px;
  font-size: 15px;
  color: #1d2129;
  resize: vertical;
  transition: border-color 0.2s ease;
}

.form-textarea:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.small-input {
  max-width: 200px;
}

.form-select {
  padding: 8px 14px;
  border: 1px solid #d0d3d9;
  border-radius: 6px;
  font-size: 14px;
  color: #1d2129;
  transition: border-color 0.2s ease;
}

.form-select:focus {
  outline: none;
  border-color: #007bff;
}

.small-select {
  width: 120px;
}

/* 头像上传样式 */
.avatar-container {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #f2f3f5;
  position: relative;
}

.detail-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-upload {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 160px;
  padding: 10px 16px;
  background-color: #f2f3f5;
  color: #4e5969;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

.upload-btn:hover {
  background-color: #e5e6eb;
  color: #1d2129;
}

.upload-input {
  display: none;
}

.image-Preview {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #f2f3f5;
  position: relative;
}

.remove-preview {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background-color 0.2s ease;
}

.remove-preview:hover {
  background-color: rgba(0, 0, 0, 0.9);
}

.upload-tip {
  font-size: 12px;
  color: #86909c;
  margin-top: 4px;
}

.count-tip {
  font-size: 12px;
  color: #86909c;
  margin-top: 4px;
  text-align: right;
}

/* 单选按钮组样式 */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  padding-top: 6px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: #1d2129;
  cursor: pointer;
}

.radio-input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.radio-text {
  transition: color 0.2s ease;
}

.radio-item:hover .radio-text {
  color: #007bff;
}

/* 按钮样式 */
.Edit-Box {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f2f3f5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-primary {
  background-color: #007bff;
  color: #fff;
}

.btn-primary:hover {
  background-color: #0069d9;
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

.btn-outline {
  background-color: #fff;
  color: #4e5969;
  border: 1px solid #d0d3d9;
}

.btn-outline:hover {
  background-color: #f2f3f5;
  color: #1d2129;
}

.btn-success {
  background-color: #28a745;
  color: #fff;
}

.btn-success:hover {
  background-color: #218838;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.2);
}

.btn-danger {
  background-color: #dc3545;
  color: #fff;
}

.btn-danger:hover {
  background-color: #c82333;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.2);
}

.btn-warning {
  background-color: #ffc107;
  color: #212529;
}

.btn-warning:hover {
  background-color: #e0a800;
  box-shadow: 0 2px 8px rgba(255, 193, 7, 0.2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 4px;
}

/* 成员管理样式 */
.member-tab-list {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f2f3f5;
}

.member-tab-item {
  font-size: 15px;
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  color: #86909c;
  padding: 0 4px;
  position: relative;
  transition: color 0.2s ease;
}

.member-tab-item:hover {
  color: #007bff;
}

.member-tab-item.active {
  color: #007bff;
  font-weight: 600;
}

.member-tab-item.active::after {
  content: '';
  position: absolute;
  bottom: -13px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #007bff;
  border-radius: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #007bff;
  color: #fff;
  font-size: 12px;
  font-weight: normal;
  margin-left: 6px;
  vertical-align: middle;
}

/* 成员操作按钮区 */
.member-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

/* 成员卡片样式 */
.member-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

/* 成员列表头部 */
.member-list-header {
  display: flex;
  background-color: #f7f8fa;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #86909c;
  border-bottom: 1px solid #f2f3f5;
}

.list-checkbox {
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.list-username {
  flex: 0 0 180px;
}

.list-remark {
  flex: 0 0 200px;
}

.list-permission {
  flex: 0 0 140px;
}

.list-operation {
  flex: 0 0 160px;
}

.list-pending {
  flex: 1;
}

/* 成员列表内容 */
.member-list-content {
  max-height: calc(100vh - 400px);
  overflow-y: auto;
}

.member-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid #f2f3f5;
  transition: background-color 0.2s ease;
}

.member-item:hover {
  background-color: #f7f8fa;
}

.member-item.leader-item {
  background-color: #f0f7ff;
}

.member-item.editing-item {
  background-color: #f0f9ff;
}

.item-checkbox {
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.member-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.item-container {
  display: flex;
  align-items: center;
  flex: 1;
}

.item-username {
  flex: 0 0 180px;
  font-size: 14px;
  color: #1d2129;
  font-weight: 500;
}

.item-remark {
  flex: 0 0 200px;
  font-size: 14px;
  color: #4e5969;
}

.remark-text {
  color: #4e5969;
}

.item-permission {
  flex: 0 0 140px;
  font-size: 14px;
}

.item-operation {
  flex: 0 0 160px;
  display: flex;
  gap: 8px;
}

.item-pending {
  flex: 1;
  font-size: 14px;
  color: #4e5969;
}

.pending-text {
  color: #4e5969;
}

/* 标签样式 */
.leader-tag {
  display: inline-block;
  padding: 2px 8px;
  background-color: #007bff;
  color: #fff;
  font-size: 12px;
  border-radius: 12px;
  margin-left: 8px;
  vertical-align: middle;
}

.permission-tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 12px;
  vertical-align: middle;
}

.admin-tag {
  background-color: #e6f7ff;
  color: #1890ff;
}

.member-tag {
  background-color: #f0f9ff;
  color: #007bff;
}

/* 成员功能区 */
.member-functions {
  padding: 12px 20px;
  background-color: #f7f8fa;
  border-top: 1px solid #f2f3f5;
}

.selected-count {
  font-size: 14px;
  color: #86909c;
}

/* 空状态样式 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #86909c;
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  color: #d0d3d9;
}

.empty-state p {
  font-size: 14px;
}

/* 不可操作文本 */
.no-operation {
  font-size: 14px;
  color: #c9cdcf;
  cursor: not-allowed;
}

/* 动画效果 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .list-remark {
    flex: 0 0 160px;
  }
}

@media (max-width: 992px) {
  .tab-container {
    width: 98%;
  }
  
  .list-username {
    flex: 0 0 140px;
  }
  
  .list-remark {
    flex: 0 0 120px;
  }
  
  .list-permission {
    flex: 0 0 120px;
  }
  
  .list-operation {
    flex: 0 0 140px;
  }
}

@media (max-width: 768px) {
  .Detail-Header {
    padding: 16px;
  }
  
  .Header-Left {
    gap: 12px;
  }
  
  .Header-Left h1 {
    font-size: 20px;
  }
  
  .tab-content {
    padding: 16px;
  }
  
  .panel-item {
    flex-direction: column;
  }
  
  .panel-label {
    width: 100%;
    padding-top: 0;
    margin-bottom: 8px;
  }
  
  .member-list-header {
    padding: 12px 16px;
    font-size: 13px;
  }
  
  .member-item {
    padding: 12px 16px;
  }
  
  .item-container {
    flex-wrap: wrap;
  }
  
  .item-username,
  .item-remark,
  .item-permission,
  .item-operation {
    flex: 0 0 100%;
    margin-bottom: 8px;
  }
  
  .item-operation {
    margin-bottom: 0;
  }
}
</style>